package com.hirisun.faces.components;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;

public class ProcessForm extends UIForm {
	static public final String COMPONENT_TYPE = "com.hirisun.faces.ProcessForm";

	public void executeCommand(String name) {
		System.out.println("ProcessForm execute. Command name: " + name);

		List<IProcessInput> inputs = new ArrayList<IProcessInput>();

		serchProcessInput(this, inputs);

		for (Iterator<IProcessInput> iterator = inputs.iterator(); iterator
				.hasNext();) {
			IProcessInput input = iterator.next();
			input.getValue();

			System.out.println("ProcessForm execute. Value: "
					+ input.getValue());
			System.out.println("ProcessForm execute. Pv: " + input.getPv());
		}
	}

	private void serchProcessInput(UIComponent container,
			List<IProcessInput> inputs) {
		List<UIComponent> children = container.getChildren();

		for (Iterator<UIComponent> iterator = children.iterator(); iterator
				.hasNext();) {
			UIComponent child = iterator.next();

			if (child instanceof IProcessInput) {
				inputs.add((IProcessInput) child);
			}

			serchProcessInput(child, inputs);
		}
	}

}
